<?php
declare(strict_types=1);

namespace App\Utils\Other\Sandpay\PaymentBehalf;

use App\Constants\Withdrawal\AccountCode;
use App\Exception\InvalidRequestException;
use App\Utils\Other\Sandpay\App;
use function Hyperf\Translation\__;

Class PaymentBehalf extends App
{
    /**
     * 路径
     * @var string
     */
    protected string $path = 'agentpay';

    /**
     * 操作
     * @param array $params
     * @param $type
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function handle(array $params, $type)
    {
        if (!in_array($type, [AccountCode::TYPE_BANK, AccountCode::TYPE_PUBLIC])) {
            throw new InvalidRequestException(__('message.withdrawal.type', [
                'type' => AccountCode::getMessage($type)
            ]));
        }
        switch ($type) {
            case AccountCode::TYPE_BANK:
                $params['accAttr'] = 0;
                $params['accType'] = 4;
                $params['productId'] = '00000004';
                break;
            case AccountCode::TYPE_PUBLIC:
                $params['accAttr'] = 1;
                $params['accType'] = 3;
                $params['productId'] = '00000003';
                break;
        }

        return $this->request($params);
    }
}